/**
 * @author: wq
 * @Date: 2017/6/1
 * @Time: 14:32
 * <p>
 * Description:
 *          ***
 */
import axios from 'axios';
import {API_NEW_VERSION} from '../api';

var qs = require('qs');

const ORDER_PAY_ALI_PAY = API_NEW_VERSION + 'alipay';
const ORDER_PAY_ACCOUNT_PAY = API_NEW_VERSION + 'account/payment';
const ORDER_PAY_UNION_PAY = API_NEW_VERSION + 'unionPay';
const ORDER_PAY_WECHAT_PAY = API_NEW_VERSION + 'wechat';
const PAYMENT = API_NEW_VERSION + 'payments/';
const ORDER_REFUND = API_NEW_VERSION + 'order/refund';

/**
 * 订单支付---支付宝支付
 * @param params
 * @returns {AxiosPromise}
 */
export const aliPay = params => {
  return axios.post(ORDER_PAY_ALI_PAY, qs.stringify({
    orderId: params.orderId,
    couponId: params.couponId,
    couponUseId: params.couponUseId
  }));
};

/**
 * 订单支付---账户余额支付
 * @param params
 * @returns {AxiosPromise}
 */
export const accountPay = params => {
  return axios.post(ORDER_PAY_ACCOUNT_PAY, qs.stringify({
    orderId: params.orderId,
    couponId: params.couponId,
    couponUseId: params.couponUseId
  }));
};

/**
 * 订单支付---银联支付
 * @param params
 * @returns {AxiosPromise}
 */
export const unionPay = params => {
  return axios.post(ORDER_PAY_UNION_PAY, qs.stringify({
    orderId: params.orderId,
    couponId: params.couponId,
    couponUseId: params.couponUseId
  }));
};

/**
 * 订单支付---微信支付
 * @param params
 * @returns {AxiosPromise}
 */
export const wechatPay = params => {
  return axios.post(ORDER_PAY_WECHAT_PAY, qs.stringify({
    orderId: params.orderId,
    couponId: params.couponId,
    couponUseId: params.couponUseId
  }));
};

export const payments = serialNo => {
  return axios.get(PAYMENT + serialNo);
};

/**
 * 订单退款
 * @param params
 * @returns {AxiosPromise}
 */
export const doOrderRefund = id => {
  return axios.post(ORDER_REFUND, qs.stringify({
    orderId: id
  }));
};
